Skip to main content

linux 账号安全管理策略

访问控制

删除多余的、过期的账号,避免被转为换共享账号。

  • 禁用账号
usermod -L user     -   禁用账号,账号将无法登陆
userdel user - 删除账号
userdel -r user - 将删除的账号和期 home 目录一起移除

记录账户历史命令,添加ip等敏感信息

# 设置当前历史命令数量
# 配置文件 /etc/profile
sed -i "s/^HISTSIZE=1000/HISTSIZE={要设置的数量}/g" /etc/profile
# 在/etc/profile的文件尾部添加如下行数配置信息,即可添加ip信息到历史命令记录
USER_IP=`who -u am i 2>/dev/null| awk '{print $NF}' |sed -e 's/[()]//g'`
if [ "$USER_IP" = "" ]
then
USER_IP=`hostname`
fi
export HISTTIMEFORMAT="%F %T $USER_IP `whoami` "
shopt -s histappend
export PROMPT_COMMAND="history -a"